package com.tqz.rc.spring.cloud.example.consumer;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * <p>
 *
 * @author tianqingzhao
 * @since 2021/9/22 10:55
 */
@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("test")
    @HystrixCommand(fallbackMethod = "error")
    public String test(String name) {
        String result = restTemplate.getForObject("http://spring-cloud-starter-tqz-rc-example-provider/provider/test?name=" + name, String.class);
        return result;
    }

    public String error(String name) {
        return "接口报错";
    }
}
